package com.panda.web.service.commons.impl;

import com.panda.web.entity.commons.Conversation;
import com.panda.web.mapper.commons.ConversationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ConversationService {

    @Autowired
    private ConversationMapper conversationMapper;

    // 保存对话记录
    public void saveMessage(String openid, String role, String content) {
        Conversation conversation = new Conversation();
        conversation.setOpenid(openid);
        conversation.setRole(role);
        conversation.setContent(content);
        conversation.setCreatedAt(LocalDateTime.now());
        conversationMapper.insert(conversation);
    }

    // 获取用户的对话历史
    public List<Conversation> getConversationHistory(String openid) {
        return conversationMapper.findByUserIdOrderByCreatedAtAsc(openid);
    }
}